import { IBizLabTemplate } from '@ibizlab/template';
import { kebabCase } from 'lodash';

/**
 * 导入登录页助手
 *
 * @export
 * @class ImportLogin
 */
export class ImportLogin{
    /**
     * Creates an instance of ImportLogin.
     * @param {IBizLabTemplate} template
     * @memberof ImportLogin
     */
    constructor(template: IBizLabTemplate) {
        template.engine.registerHelper('ImportLogin', (...args: any[]) => {
            let result = "component: () => import('@components/function/login/src/login.vue')";
            const pages: any[] = args[0];
            let loginPage = null;
			if (pages && pages.length > 0) {
                for (let index = 0; index < pages.length; ++index) {
                    if (pages[index].refFlag && Object.is(pages[index].viewType, "APPLOGINVIEW")) {
                        loginPage = pages[index];
                        break;
                    }
                }
            }
            if (loginPage) {
                if (loginPage.psAppModule) {
                    result = `component: () => import("@views/${kebabCase(loginPage.psAppModule.codeName)}/${kebabCase(loginPage.codeName)}/${kebabCase(loginPage.codeName)}.vue")`;
                } else {
                    result = `component: () => import("@views/${kebabCase(loginPage.codeName)}/${kebabCase(loginPage.codeName)}.vue")`;
                }
            }
			return result;
		});
    }
}